﻿using System.Collections.Generic;
using System.Web.Mvc;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json;
using System.Data;
using StrokeCenterSystem.Bll;

namespace StrokeCenterSystem
{
    public class BaseController : Controller
    {
        /// <summary>
        /// 登录用户信息
        /// </summary>
        public SysLoginUser loginUser
        {
            get {
                return LoginManager.GetLoginUser();
            }
        }
        /// <summary>
        /// 允许使用get方法调用json
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        protected JsonResult JSON(object data)
        {
            return base.Json(data, JsonRequestBehavior.AllowGet);
        }

        public ActionResult GetLoginUserInfo()
        {
            return JsonDate(loginUser);
        }

        /// <summary>
        /// 返回处理过的时间的Json字符串
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public ContentResult JsonDate(object date)
        {
            var timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };

            return Content(JsonConvert.SerializeObject(date, Formatting.Indented, timeConverter));
        }

        public ContentResult JsonFilerNull(object date)
        {
            var jSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };

            return Content(JsonConvert.SerializeObject(date, Formatting.Indented, jSetting));
        }
    }
}